package com.rh.gtoa.common.controller;

import com.rh.gtoa.common.service.FileManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.Objects;
@CrossOrigin
@RestController
@Api(tags = "文件服务")
public class FileController {
    @Autowired
    private FileManageService fileManageService;

    @ApiOperation(value = "上传文件以便打开")
    @PostMapping("/uploadToNginxForOpen")
    public String uploadToNginxForOpen(@RequestParam("file") MultipartFile file,String modelName) {
        if (file==null){
            return "文件上传失败，请重新选择文件";
        }
        return fileManageService.uploadToNginxForOpen(file,modelName);
    }
    @ApiOperation(value = "上传文件以便下载")
    @PostMapping("/uploadToNginxForDownload")
    public String uploadToNginxForDownload(@RequestParam("file") MultipartFile file,String modelName) {
        if (file==null){
            return "文件上传失败，请重新选择文件";
        }
        return fileManageService.uploadToNginxForDownload(file,modelName);
    }
    
    
    
   /*@ApiOperation(value = "上传")
    @PostMapping("/upload")
    public String fileUpload(@RequestParam("file") MultipartFile file,String modelName){
        if (file==null){
            return "文件上传失败，请重新选择文件";
        }
        return fileManageService.upload(file,modelName);
    }
    @ApiOperation(value = "下载")
    @GetMapping("/download")
    public String fileDownload(@RequestParam("fileName") String fileName, HttpServletResponse response){
        if (Objects.isNull(fileName)){
            return "文件下载失败，请选择文件要下载的文件";
        }
        return fileManageService.download(fileName, response);
    }
    @ApiOperation(value = "预览")
    @GetMapping("/showImage")
    public String showImage(@RequestParam("fileName") String fileName, HttpServletResponse response){
        if (Objects.isNull(fileName)){
            return "文件下载失败，请选择文件要下载的文件";
        }
        return fileManageService.showImage(fileName, response);
    }*/
}
